package com.hspedu.newData.dmsxl.链表;

import com.hspedu.newData.dmsxl.ds.ListNode;

import java.util.Arrays;

/**
 * @Author: yh
 * @description: 
 * @CreateTime: 2025-05-09 
 * @Version: 1.0
 */

public class LC148排序链表 {

    // todo 常数级空间复杂度无法实现
    public ListNode sortList(ListNode head) {

        int[] a = new int[50000];

        int i = 0;

        ListNode p = head;
        while (p!=null){
            a[i++] = p.val;
            p = p.next;
        }

        Arrays.sort(a,0,i);

        p = head;

        i = 0;

        while (p!=null){
            p.val = a[i++];
            p = p.next;
        }
        return head;
    }
}
